import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore("user", () => {
    //存储用户是否登录
    const loginState = ref(window.localStorage.getItem('loginState') === "true")

    //修改用户是否登录
    function setLoginState(type: boolean) {
        loginState.value = type
    }

    //存储用户id
    const userid = ref(
        window.localStorage.getItem("userid") || "用户id的默认值"
    )
    function setUserId(id: string) {
        userid.value = id
    }

    return {
        loginState,
        setLoginState,
        userid,
        setUserId,
    }
})